import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

// 这样的写法居然是用来按需加载 https://router.vuejs.org/zh-cn/advanced/lazy-loading.html  妈的写法就是这样，我还以为这个resolve 是什么吊东西。
const router = new Router({
    routes: [
        {
            path: '/',
            redirect: '/login'
        },
        {
            path: '/home',
            component: resolve => require(['../components/common/Home.vue'], resolve),
            children:[
                {
                    path: '/',
                    component: resolve => require(['../components/page/Readme.vue'], resolve)
                },
                {
                    path: '/basetable',
                    component: resolve => require(['../components/page/BaseTable.vue'], resolve)
                },
                {
                    path: '/vuetable',
                    component: resolve => require(['../components/page/VueTable.vue'], resolve)     // vue-datasource组件
                },
                {
                    path: '/baseform',
                    component: resolve => require(['../components/page/BaseForm.vue'], resolve)
                },
                {
                    path: '/vueeditor',
                    component: resolve => require(['../components/page/VueEditor.vue'], resolve)    // Vue-Quill-Editor组件
                },
                {
                    path: '/markdown',
                    component: resolve => require(['../components/page/Markdown.vue'], resolve)     // Vue-Quill-Editor组件
                },
                {
                    path: '/upload',
                    component: resolve => require(['../components/page/Upload.vue'], resolve)       // Vue-Core-Image-Upload组件
                },
                {
                    path: '/basecharts',
                    component: resolve => require(['../components/page/BaseCharts.vue'], resolve)   // vue-echarts-v3组件
                },
                {
                    path: '/mixcharts',
                    component: resolve => require(['../components/page/MixCharts.vue'], resolve)    // vue-echarts-v3组件
                },
                {
                    path: '/Cdn',
                    component: resolve => require(['../components/page/Cdn.vue'], resolve)    // 刷新cdn
                },
                {
                    path: '/CreateOperPage',
                    component: resolve => require(['../components/page/CreateOperPage.vue'], resolve)    // 生成专场页面
                }

            ],
            beforeEnter: (to,form,next) =>{
                if (!sessionStorage.getItem('access')) {
                    next({
                        path: '/login'
                    })
                }else{
                  next();
                }   
            }
        },
        {
            path: '/login',
            component: resolve => require(['../components/page/Login.vue'], resolve)
        },
    ]
})

// console.log(resolve => require(['../components/page/Login.vue'], resolve));
export default router